import { PlusOutlined } from '@ant-design/icons';
import { Button, Input } from 'antd';
import React, { useState, useRef } from 'react';
import { PageContainer } from '@ant-design/pro-layout';
import ProTable from '@ant-design/pro-table';

import { queryRule } from './service';
import { money_trans } from '@/utils/utils';

const TableList = () => {
  const [count, setCount] = useState()
  const actionRef = useRef();
  const columns = [
    {
      title: '单据号',
      dataIndex: 'number',
      render: (dom, entity) => {
        return <a>{dom}</a>;
      },
    },
    {
      title: '退款店铺',
      dataIndex: 'storeName',
      valueType: 'textarea',
    },
    {
      title: '退款金额',
      dataIndex: 'amount',
      hideInForm: true,
      render:(dom)=>{
        return money_trans(dom,true)
      }
    },
    {
      title: '扣除金额',
      dataIndex: 'deductAmount',
      hideInForm: true,
    },
    {
      title: '审核状态',
      dataIndex: 'status',
      hideInForm: true,
      valueEnum: {
        0: {
          text: '未审核',
          status: 'Default',
        },
        1: {
          text: '已审核',
          status: 'Processing',
        },
      },
    },
    {
      title: '充值时间',
      dataIndex: 'created_at',
      hideInTable: true,
      valueType: 'dateRange',
      search: {
        transform: (value) => {
          return {
            startTime: value[0],
            endTime: value[1],
          };
        },
      },
    },
    {
      title: '退款时间',
      dataIndex: 'createTime',
      hideInForm: true,
      hideInSearch: true,
      render:(dom)=>{return <div>{new Date(dom).toLocaleString()}</div>}
    },
    {
      title: '查看单据',
      dataIndex: 'action',
      valueType: 'text',
    },
  ];
  return (
    <PageContainer>
      <ProTable
        headerTitle="退款记录"
        scroll={{x:1200}}
        actionRef={actionRef}
        rowKey="id"
        bordered
        search={{
          labelWidth: 120,
        }}
        request={(params, sorter, filter) => queryRule({ ...params, sorter, filter })}
        postData={(payload) => {
          const { list, total } = payload;
          setCount(total)
          return list;
        }}
        columns={columns}
        pagination={{
          defaultPageSize: 30,
          showSizeChanger: false,
          showTitle: false,
          total: count,
          showTotal: (total) => `共${total}条`,
        }}
      />
    </PageContainer>
  );
};

export default TableList;
